<?php

namespace common\models\db\tables;

use Yii;

/**
 * This is the model class for table "{{%equipment}}".
 *
 * @property string $id
 * @property string $uuid 设备唯一标识
 * @property string $os_type 操作系统
 * @property string $name 设备名称
 * @property string $brand 品牌
 * @property string $model 型号
 * @property string $system 系统
 * @property string $system_version 版本号
 * @property string $kernel_version 内核版本
 * @property string $hardware_version 硬件版本
 * @property string $cpu cpu
 * @property int $ram_size 运行内存
 * @property int $rom_size 设备容量
 * @property string $app_version_id 安装的该应用版本ID
 * @property int $last_app_use_at 最后应用使用时间
 *
 * @property EquipmentAppVersion $appVersion
 * @property EquipmentAppVersionUpdateLog[] $equipmentAppVersionUpdateLogs
 * @property EquipmentOperateLog[] $equipmentOperateLogs
 * @property EquipmentUser[] $equipmentUsers
 * @property User[] $users
 */
class Equipment extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%equipment}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['uuid', 'last_app_use_at'], 'required'],
            [['ram_size', 'rom_size', 'app_version_id', 'last_app_use_at'], 'integer'],
            [['uuid'], 'string', 'max' => 191],
            [['os_type'], 'string', 'max' => 50],
            [['name', 'brand', 'model', 'system', 'system_version', 'kernel_version', 'hardware_version', 'cpu'], 'string', 'max' => 255],
            [['uuid'], 'unique'],
            [['app_version_id'], 'exist', 'skipOnError' => true, 'targetClass' => EquipmentAppVersion::className(), 'targetAttribute' => ['app_version_id' => 'id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'uuid' => Yii::t('app', '设备唯一标识'),
            'os_type' => Yii::t('app', '操作系统'),
            'name' => Yii::t('app', '设备名称'),
            'brand' => Yii::t('app', '品牌'),
            'model' => Yii::t('app', '型号'),
            'system' => Yii::t('app', '系统'),
            'system_version' => Yii::t('app', '版本号'),
            'kernel_version' => Yii::t('app', '内核版本'),
            'hardware_version' => Yii::t('app', '硬件版本'),
            'cpu' => Yii::t('app', 'cpu'),
            'ram_size' => Yii::t('app', '运行内存'),
            'rom_size' => Yii::t('app', '设备容量'),
            'app_version_id' => Yii::t('app', '安装的该应用版本ID'),
            'last_app_use_at' => Yii::t('app', '最后应用使用时间'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getAppVersion()
    {
        return $this->hasOne(EquipmentAppVersion::className(), ['id' => 'app_version_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getEquipmentAppVersionUpdateLogs()
    {
        return $this->hasMany(EquipmentAppVersionUpdateLog::className(), ['equipment_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getEquipmentOperateLogs()
    {
        return $this->hasMany(EquipmentOperateLog::className(), ['equipment_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getEquipmentUsers()
    {
        return $this->hasMany(EquipmentUser::className(), ['equipment_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUsers()
    {
        return $this->hasMany(User::className(), ['id' => 'user_id'])->viaTable('{{%equipment_user}}', ['equipment_id' => 'id']);
    }
}
